use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
use yata::core::PeriodType;
use yata::core::ValueType;

use super::IndicatorActionWrap;

///
/// Struct to hold the results of The Aso Awesome Oscillator indicator calculations.
/// Struct yata::indicators::AwesomeOscillator
///
///  参见[ASO](https://www.tradingview.com/scripts/awesomeoscillator/)
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct ASO {
    /// 2 signals
    /// “Twin Peaks”. When value is below zero line and we got conseq_peaks lower peaks, then returns full positive signal
    /// When value is above zero line and we got conseq_peaks higher peaks, then returns full negative signal. Otherwise gives no signal.
    pub signal0: Option<IndicatorActionWrap>,

    /// Gives signal when values crosses zero line
    pub signal1: Option<IndicatorActionWrap>,

    /// 1 value
    /// Absolute difference between fast and slow periods MA
    /// Range in (-inf; +inf)
    pub dif: ValueType,
}

/// Configuration for Struct yata::indicators::AwesomeOscillator, Awesome Oscillator
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct ASOConfig {
    /// ma1: M
    /// Default is SMA(34)
    ///
    /// Period range in (ma2’s period; PeriodType::MAX).
    ///
    pub ma1: PeriodType,

    /// ma2: M
    /// Default is SMA(5)
    ///
    /// Period range in [3; ma1’s period).
    ///
    pub ma2: PeriodType,
    /// source: Source
    /// Default is HL2. (High+Low)/2 part of a candle
    ///
    // pub source: yata::core::Source,

    /// left: PeriodType
    /// Default is 1.
    ///
    /// Range in [1; PeriodType::MAX-right).
    ///
    pub left: PeriodType,
    /// right: PeriodType
    /// Default is 1.
    ///
    /// Range in [1; PeriodType::MAX-left).
    pub right: PeriodType,
    ///
    /// conseq_peaks: u8
    /// Default is 2.
    ///
    /// Range in [1; PeriodType::MAX].
    pub conseq_peaks: u8,
}

impl Default for ASOConfig {
    fn default() -> Self {
        Self {
            ma1: 34,
            ma2: 5,
            // source: todo!(),
            left: 1,
            right: 1,
            conseq_peaks: 2,
        }
    }
}
